package com.pand.service;

import com.pand.model.order.Order;
import com.pand.model.vehicle.RentVehicle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by lh on 2017/11/3.
 */
public interface VehicleService extends JpaRepository<RentVehicle, Long> {
    @Query("select count(distinct v.license) from RentVehicle v, BaseVehicle bv, VehicleRealData vrd ,VehicleType vt " +
            "where v.vinCode = vrd.vin " +
            "and v.vehicleId = bv.id " +
            "and bv.vehicleTypeId = vt.id " +
            "and v.organizationId = 4 " +
            "and vrd.online = 1 " +
            "and vt.vehicleNetworkType = 'lZVehicle'")
    long getVehicleTotalAmount();

    @Query("select count(distinct v.license) from RentVehicle v,BaseVehicle bv, VehicleRealData vrd ,VehicleType vt " +
            "where v.vinCode = vrd.vin " +
            "and v.vehicleId = bv.id " +
            "and bv.vehicleTypeId = vt.id " +
            "and vrd.online = 1 " +
            "and v.organizationId = 4" +
            "and v.operateStatus = ?1 "+
            "and vt.vehicleNetworkType = 'lZVehicle'")
    long getVehicleAmount(Integer operateStatus);

    @Query("select count(distinct v.license) from RentVehicle v,BaseVehicle bv, VehicleRealData vrd ,VehicleType vt " +
            "where v.vinCode = vrd.vin " +
            "and v.vehicleId = bv.id " +
            "and bv.vehicleTypeId = vt.id " +
            "and vrd.online = 1 " +
            "and v.organizationId = 4 " +
            "and v.operateStatus <> 1050 " +
            "and v.operateStatus <> 1000 " +
            "and v.operateStatus <> 1070 " +
            "and v.operateStatus <> 1204 " +
            "and v.operateStatus <> 1206 " +
            "and v.operateStatus <> 1202 " +
            "and v.operateStatus <> 1080 " +
            "and v.operateStatus <> 1208 " +
            "and v.operateStatus <> 1401 " +
            "and vt.vehicleNetworkType = 'lZVehicle'")
    long getOtherVehicleAmount();

//    @Query("select v.vehicleId,v.license,v.vinCode,vrd.longtitude,vrd.latitude,vrd.odo from RentVehicle v, VehicleRealData vrd " +
//            "where v.vinCode = vrd.vin " +
//            "and v.organizationId = 4")
    List<Object> findRealLocation(int page, int size);

    RentVehicle findByVehicleId(Long vehicleId);
}
